package me.lensfrex.vegetables;

import me.lensfrex.vegetables.data.Vegetable;
import me.lensfrex.vegetables.resopnse.ResponseProcessor;
import me.lensfrex.vegetables.resopnse.UnityResponse;

import java.util.ArrayList;

public class VegetablesMain {

    // 如果要使用其他目录的测试数据文件，请在命令行指定参数（第一个参数）
    // 否则将会使用默认的目录("/{运行目录，一般为工程目录}/vegetables/resources/vegetables.txt")
    // 此项目的idea runConfigure已经设置好运行目录，一般情况下可以直接读取到
    public static void main(String[] args) {
        new VegetablesMain().run(args);
    }

    private void run(String[] args) {
        UnityResponse<ArrayList<Vegetable>> response = null;
        ResponseProcessor responseProcessor = null;

        // 测试数据部分不正确时
        responseProcessor = new ResponseProcessor(System.getProperty("user.dir") + "/resources/worn.txt");
        response = responseProcessor.getListPage(1, 10);
        System.out.println("------------------------------------");
        System.out.println("测试：数据部分不正确时");
        System.out.println(response);
        System.out.println("------------------------------------");

        // 测试数据为空时
        responseProcessor = new ResponseProcessor(System.getProperty("user.dir") + "/resources/empty.txt");
        response = responseProcessor.getListPage(1, 10);
        System.out.println("------------------------------------");
        System.out.println("测试：数据空时");
        System.out.println(response);
        System.out.println("------------------------------------");

        if (args.length != 0) {
            System.out.println("Read source data from: " + args[0]);
            responseProcessor = new ResponseProcessor(args[0]);
        } else {
            String sourceDataLocation = System.getProperty("user.dir") + "/resources/vegetables.txt";
            System.out.println("Command line param not specify, will read source data from: " + sourceDataLocation);
            responseProcessor = new ResponseProcessor(sourceDataLocation);
        }

        // 测试正常情况
        response = responseProcessor.getListPage(1,10);
        System.out.println("------------------------------------");
        System.out.println("测试：正常情况(page 1, pageSize 10)");
        System.out.println(response);

        response = responseProcessor.getListPage(2,10);
        System.out.println("------------------------------------");
        System.out.println("测试：正常情况(page 2, pageSize 10)");
        System.out.println(response);

        response = responseProcessor.getListPage(1,15);
        System.out.println("------------------------------------");
        System.out.println("测试：正常情况(page 1, pageSize 15)");
        System.out.println(response);

        response = responseProcessor.getListPage(2,15);
        System.out.println("------------------------------------");
        System.out.println("测试：正常情况(page 2, pageSize 15)");
        System.out.println(response);

        // 测试页码超限
        response = responseProcessor.getListPage(100000, 100);
        System.out.println("------------------------------------");
        System.out.println("测试：页码超限");
        System.out.println(response);

        // 测试分页参数有误
        response = responseProcessor.getListPage(-1, 150);
        System.out.println("------------------------------------");
        System.out.println("测试：参数有误");
        System.out.println(response);

        // 测试炒饭...
        System.out.println("------------------------------------");
        System.out.println("测试：点炒饭");
        System.out.println("炸了");
    }
}
